using DataFrames

# 定义SRS结构体，将 Double 替换为 Float64
struct SRS
    SRSPeriod::Vector{Int}
    ResourceType::String
    NRB::Float64
    NRBPerTransmission::Float64
    BandwidthConfigurationTable::DataFrame
    SubcarrierOffsetTable::DataFrame
    StartRBHoppingTable::DataFrame
    NumSRSPorts::Float64
    SymbolStart::Float64
    NumSRSymbols::Float64
    FrequencyStart::Float64
    NRRC::Float64
    FrequencyScalingFactor::Float64
    EnableStartRBHopping::Bool
    StartRBIndex::Float64
    CSRSOffset::Float64
    BSRSOffset::Float64
    BHop::Float64
    Repetition::Float64
    KTC::Float64
    KBarTC::Float64
    CyclicShift::Float64
    GroupSeqHopping::String
    NSRSID::Float64
    SRSPositioning::Bool
    EnableEightPortTDM::Bool
    CyclicShiftHopping::Bool
    CyclicShiftHoppingID::Float64
    CyclicShiftHoppingSubset::Vector{Float64}
    HoppingFilterGranularity::Bool
    CombOffsetHopping::Bool
    CombOffsetHoppingID::Float64
    CombOffsetHoppingSubset::Vector{Float64}
    HoppingWithRepetition::Bool
end

# 创建示例表格数据
bandwidth_table = DataFrame(rand(64, 9), :auto)
subcarrier_table = DataFrame(rand(3, 6), :auto)
start_rb_table = DataFrame(rand(4, 4), :auto)

# 创建SRS结构体实例，修正参数名和类型匹配问题
srs_example = SRS(
    [10, 3],  # SRSPeriod
    "periodic",  # ResourceType
    48.0,  # NRB
    48.0,  # NRBPerTransmission
    bandwidth_table,  # BandwidthConfigurationTable
    subcarrier_table,  # SubcarrierOffsetTable
    start_rb_table,  # StartRBHoppingTable
    1.0,  # NumSRSPorts
    12.0,  # SymbolStart
    1.0,  # NumSRSymbols
    0.0,  # FrequencyStart
    0.0,  # NRRC
    1.0,  # FrequencyScalingFactor
    true,  # EnableStartRBHopping
    0.0,  # StartRBIndex
    13.0,  # CSRSOffset
    0.0,  # BSRSOffset
    1.0,  # BHop
    1.0,  # Repetition
    4.0,  # KTC
    0.0,  # KBarTC
    0.0,  # CyclicShift
    "neither",  # GroupSeqHopping
    0.0,  # NSRSID
    false,  # SRSPositioning
    false,  # EnableEightPortTDM
    false,  # CyclicShiftHopping
    0.0,  # CyclicShiftHoppingID
    Float64[],  # CyclicShiftHoppingSubset
    false,  # HoppingFilterGranularity
    false,  # CombOffsetHopping
    0.0,  # CombOffsetHoppingID
    Float64[],  # CombOffsetHoppingSubset
    false  # HoppingWithRepetition
)

# 定义 hSRSCDMLengths 函数，用于计算给定 SRS 配置的 CDM 长度
function hSRSCDMLengths(srs)
    
    # TS 38.211 Section 6.4.1.4.2, definition of N_ap_bar
    N_ap_bar = if srs.EnableEightPortTDM
        4
    else
        srs.NumSRSPorts
    end
    
    # TS 38.211 Section 6.4.1.4.3, position in comb per port
    halfPorts = ((N_ap_bar == 8 && srs.KTC == 4) ||
                 (N_ap_bar == 8 && srs.KTC == 2 && srs.CyclicShift >= 4) ||
                 (N_ap_bar == 4 && srs.KTC == 8) ||
                 (N_ap_bar == 4 && srs.KTC == 4 && srs.CyclicShift >= 6) ||
                 (N_ap_bar == 4 && srs.KTC == 2 && srs.CyclicShift >= 4))
    divfd = if halfPorts
        2
    elseif N_ap_bar == 8 && srs.KTC == 8
        4
    else
        1
    end

    F = N_ap_bar / divfd

    cdmLengths = [F, 1]

    return cdmLengths
end

result = hSRSCDMLengths(srs_example)
println(result)